package pers.cj.pdos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import pers.cj.pdos.cache.CacheData;
import pers.cj.pdos.cache.CacheRemove;
import pers.cj.pdos.cache.CacheRemoveMore;
import pers.cj.pdos.entity.AttrName;
import pers.cj.pdos.mapper.AttrNameMapper;
import pers.cj.pdos.service.IAttrNameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.cj.pdos.vo.AttrNameVo;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
@Service
public class AttrNameServiceImpl extends ServiceImpl<AttrNameMapper, AttrName> implements IAttrNameService {
    @Autowired
    AttrNameMapper attrNameMapper;
    @Override
    @CacheData(clazz = AttrNameServiceImpl.class, param = "#companyId")
    public List<AttrNameVo> listVo(String companyId) {
        return attrNameMapper.listVo(companyId);
    }

    @Override
    @CacheData(clazz = AttrNameServiceImpl.class, param = "#companyId")
    public List<AttrName> list(String companyId) {
        return attrNameMapper.selectList(new QueryWrapper<AttrName>().eq("company_id",companyId).orderByAsc("sort"));
    }

    @Override
    public boolean checkName(String name, String companyId) {
        return attrNameMapper.selectCount(new QueryWrapper<AttrName>().eq("company_id",companyId).eq("name",name)) > 0;
    }

    @Override
    @CacheRemoveMore(cacheRemoves = {
            @CacheRemove(clazz = AttrNameServiceImpl.class, methodName = "list", param = "#attrName.companyId"),
            @CacheRemove(clazz = AttrNameServiceImpl.class, methodName = "listVo", param = "#attrName.companyId")
    })
    public void update(AttrName attrName) {
        attrNameMapper.updateById(attrName);
    }
}
